package com.bang.study.singleton;

import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * @ClassName: SingletonExample3
 * @Desc: 单例模式 枚举
 * @author: BANG
 * @Date: 2019/10/28 12:57
 * @Version: 1.0
 * @Modified By:
 */
public class SingletonExample3 {


    private SingletonExample3() {

    }

    public static SingletonExample3 getInstance() {
        return Singleton.INSTANCE.getInstance();
    }


    private enum Singleton {
        INSTANCE;


        private SingletonExample3 instance;

        Singleton() {
            this.instance = new SingletonExample3();
        }

        public SingletonExample3 getInstance() {
            return instance;
        }

    }

    public static void main(String[] args) {
        PriorityBlockingQueue<Integer> queue = new PriorityBlockingQueue<Integer>(1000, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2.compareTo(o1);
            }
        });
        queue.add(1);
        queue.add(11);
        queue.add(111);
        queue.add(1111);
        queue.add(111111);
        queue.add(2);
        while (!queue.isEmpty()) {
            Integer poll = queue.poll();
            System.out.println(poll);
        }

    }

}
